# binary_to_text.py

# Creates a function that converts 8 bit binary code back to text
def binary_to_text(binary_str):
    """Convert binary string (8 bits per character) to text."""
    # Remove spaces if present
    binary_str = binary_str.replace(" ", "")
    
    # Ensure the length is a multiple of 8
    if len(binary_str) % 8 != 0:
        raise ValueError("Binary string length must be a multiple of 8.")
    
    text = ''
    for i in range(0, len(binary_str), 8):
        byte = binary_str[i:i+8]
        char = chr(int(byte, 2))
        text += char
    return text

# Prompts user to enter binary code to be converted back into text
if __name__ == "__main__":
    binary_input = input("Enter binary code to convert to text: ")
    try:
        text_output = binary_to_text(binary_input)
        print(f"\nDecoded Text:\n{text_output}")
    except ValueError as e:
        print(f"\nError: {e}")
